package ru.amse.vlassiev.TestPackage;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import ru.amse.vlassiev.reader.*;
import junit.framework.TestCase;

public class LogFileReaderTest extends TestCase {

	public LogFileReaderTest(String name) {
		super(name);
	}

	public void testLogFileReaderFileInt() {
		try {
			LogFileReader reader = new LogFileReader(new File("test"), 100);
		} catch (Exception e) {
			fail("Input is good, but exception is thrown.");
		}
	}

	public void testLogFileReaderBadInput() {
		try {
			LogFileReader reader = new LogFileReader(new File("badinput"), 100);
			fail("Input is bad, but exception isn't thrown.");
		} catch (Exception e) {
		}
	}

	public void testLogFileReaderFile() {
		try {
			LogFileReader reader = new LogFileReader(new File("test"),1000);
		} catch (Exception e) {
			fail("Input is good, but exception is thrown.");
		}
	}

	public void testGetNextMessage() {
		try {
			LogFileReader reader = new LogFileReader(new File("test"));
			Map<String, String> message = reader.getNextMessage();
			assertEquals(message.get("srcip"), "10.3.62.2");
		} catch (FileNotFoundException e) {
			fail("Input is good, but exception is thrown.");
		}
	}

	public void testGetNextMessageNotEquals() {
		try {
			LogFileReader reader = new LogFileReader(new File("test"));
			Map<String, String> message = reader.getNextMessage();
			assertNotSame(message.get("srcip"), "abrakadabra");
		} catch (FileNotFoundException e) {
			fail("Input is good, but exception is thrown.");
		}
	}

	public void testGetNextMessagePsh() {
		try {
			LogFileReader reader = new LogFileReader(new File("test"));
			Map<String, String> message = reader.getNextMessage();
			assertEquals(message.get("psh"), "1");
		} catch (Exception e) {
			fail("Input is good, but exception is thrown.");
		}
	}

}
